/*
 * Camera.cpp
 *
 *  Created on: May 13, 2012
 *      Author: mklingen
 */

#include "Camera.h"
#include <iostream>


namespace kling
{

    Camera::Camera(double width, double height)
    {
        m_view = new sf::View(sf::Vector2f(0,0), sf::Vector2f(width/2, height/2));
        m_position = Eigen::Vector2d(0,0);
        m_velocity = Eigen::Vector2d(0,0);
        m_isKeyPressed[Qt::Key_W] = false;
        m_isKeyPressed[Qt::Key_A] = false;
        m_isKeyPressed[Qt::Key_S] = false;
        m_isKeyPressed[Qt::Key_D] = false;

    }

    Camera::~Camera()
    {
        if(m_view != NULL)
        {
            delete m_view;
            m_view = NULL;
        }

    }

    void Camera::Update(double dt)
    {
        Move(m_velocity * dt);

        if(IsKeyPressed(Qt::Key_W))
        {
            Accelerate(Eigen::Vector2d(0, 20));
        }
        else if(IsKeyPressed(Qt::Key_S))
        {
            Accelerate(Eigen::Vector2d(0, -20));
        }

        if(IsKeyPressed(Qt::Key_A))
        {
           Accelerate(Eigen::Vector2d(-20, 0));
        }
        else if(IsKeyPressed(Qt::Key_D))
        {
            Accelerate(Eigen::Vector2d(20, 0));
        }

        m_velocity *= 0.9;
    }

    void Camera::HandleKeyEvent(QKeyEvent* keyEvent)
    {
        if(keyEvent->type() == QKeyEvent::KeyPress)
        {
            m_isKeyPressed[keyEvent->key()] = true;
        }
        else if(keyEvent->type() == QKeyEvent::KeyRelease)
        {
            m_isKeyPressed[keyEvent->key()] = false;
        }
    }

    void Camera::HandleMouseEvent(QMouseEvent* mouseEvent)
    {
        // Do nothing
    }

} /* namespace kling */
